import {Component, Input} from '@angular/core';
import {FormsModule} from "@angular/forms";
import {NgForOf} from "@angular/common";
import {NzButtonComponent} from "ng-zorro-antd/button";
import {NzCardComponent} from "ng-zorro-antd/card";
import {NzColDirective, NzRowDirective} from "ng-zorro-antd/grid";
import {NzDatePickerComponent, NzRangePickerComponent} from "ng-zorro-antd/date-picker";
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
import {NzInputDirective} from "ng-zorro-antd/input";
import {NzOptionComponent, NzSelectComponent} from "ng-zorro-antd/select";
import {NzSpaceComponent, NzSpaceItemDirective} from "ng-zorro-antd/space";
import {NzTableCellDirective, NzTableComponent, NzTbodyComponent, NzTrDirective} from "ng-zorro-antd/table";
import {NzWaveDirective} from "ng-zorro-antd/core/wave";
import {NzMessageService} from 'ng-zorro-antd/message';
import {CamundaService} from '../../../services/camunda.service';

@Component({
  selector: 'app-ask-for-level-supervisor',
  standalone: true,
  imports: [
    FormsModule,
    NgForOf,
    NzButtonComponent,
    NzCardComponent,
    NzColDirective,
    NzDatePickerComponent,
    NzFormControlComponent,
    NzFormDirective,
    NzFormItemComponent,
    NzFormLabelComponent,
    NzInputDirective,
    NzOptionComponent,
    NzRangePickerComponent,
    NzRowDirective,
    NzSelectComponent,
    NzSpaceComponent,
    NzTableCellDirective,
    NzTableComponent,
    NzTbodyComponent,
    NzTrDirective,
    NzWaveDirective,
    NzSpaceItemDirective
  ],
  templateUrl: './ask-for-level-supervisor.component.html',
  styleUrl: './ask-for-level-supervisor.component.css'
})
export class AskForLevelSupervisorComponent {
  constructor(private camundaService: CamundaService,
              private messageService: NzMessageService) {
  }

  //从父层传过来的 taskId
  @Input() taskId:String = "";

  //任务相关信息，用来回显页面
  taskMessage = {
    startTime: "",
    instanceId: "",
    processName: "",
    variables: {
      "starter":"",
      "reason":"",
      "rangePicker": [],
      "type": ""
    },
    nodes:<any>[]
  }

  currentOpinion= "";

  ngOnInit(): void {
    this.camundaService.task_message(this.taskId).subscribe(res => {
      this.taskMessage = res;
    })
  }

  //通过按钮
  pass(): void{
    console.log(this.currentOpinion)
    this.camundaService.pass_supervisor(this.taskId, this.currentOpinion).subscribe();
    this.messageService.create("success", "流程审批已通过");
  }

  //驳回按钮
  reject(): void{
    console.log(this.currentOpinion)
    this.camundaService.reject_supervisor(this.taskId, this.currentOpinion).subscribe();
    this.messageService.create("success", "流程审批已驳回")
  }
}
